package org.chen.ctrip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.chen.common.ctrip.crawler.CrawlerTaskLog;
import org.chen.ctrip.mapper.CrawlerTaskLogMapper;
import org.chen.ctrip.service.CrawlerTaskLogService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

// CrawlerTaskLogServiceImpl.java
@Slf4j
@Service
public class CrawlerTaskLogServiceImpl extends ServiceImpl<CrawlerTaskLogMapper, CrawlerTaskLog> implements CrawlerTaskLogService {

    @Override
    public List<CrawlerTaskLog> findByTaskId(Long taskId, int limit) {
        QueryWrapper<CrawlerTaskLog> wrapper = new QueryWrapper<>();
        wrapper.eq("task_id", taskId);
        wrapper.orderByDesc("create_time");
        wrapper.last("LIMIT " + limit);
        return list(wrapper);
    }
}